#include "dkglDrawable.h"
#include "dkglPreRequest.h"
#include "dkglUtility.h"
#include "dkglDrawList.h"
#include "dkglBounding.h"

namespace DKGL
{
    Drawable::Drawable(const String& name):
        _name(name),
		_bounding(NULL),
		_showBounding(false),
		_show(true)
    {
		SetIdentityMatrix(_worldTransformation);
    }


    Drawable::~Drawable()
    {

    }


    void Drawable::setWorldTransformation(const float* worldTransformation)
    {
        CopyMatrix(_worldTransformation, worldTransformation);

		if (_bounding)
		{
			_bounding->setWorldTransformation(worldTransformation);
		}
    }


	void Drawable::renderImpl()
	{
		glLoadMatrixf(_worldTransformation);
	}

    void Drawable::render()
    {
        if (_show)
		{
			DrawList::Instance().add(this);
		}

		if (_showBounding && _bounding)
		{
			DrawList::Instance().add(_bounding->getDrawable());
		}

        // TODO: draw axes and bounding box here
    }//Endof render


	void Drawable::showBounding(bool b)
	{
		_showBounding = b;

		if (_bounding)
			_bounding->show(b);
	}


}//namespace DKGL